/*
 * 文件名称: ArgInfo.java
 * 版权信息: Copyright 2001-2012 ZheJiang Collaboration Data System Co., LTD. All right reserved.
 * ----------------------------------------------------------------------------------------------
 * 修改历史:
 * ----------------------------------------------------------------------------------------------
 * 修改原因: 新增
 * 修改人员: huangwb
 * 修改日期: 2012-3-1
 * 修改内容: 
 */
package com.huangwb.person.bean;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.huangwb.person.util.TemlateEnum;


/**
 * 生成文件的请求参数
 * 
 * @author <a href="mailto:huangwb@zjcds.com">huangwb</a> created on 2012-3-1
 * @since DE6.0
 */
public class ArgInfo {
    /**生成的类名*/
    private String className;
    /**表名*/
    private String tableName;
    /**包名*/
    private String pck;
    
    private String genType;

    /**sql文件路径或者字段文件路径*/
    private String sqlFilePath;
    /**输出文件集合*/
    private Map<String,String> outputInfos = new HashMap<String,String>();
    
    public ArgInfo() {}
    
    
    public void setOutputInfo(OutputFile outputFile) {
    	String outputType = outputFile.getOutputType() ;
    	String outPath = outputFile.getProjectPath();
    	if(StringUtils.isNotBlank(outPath)){
    		outPath = outPath.replaceAll("\\\\", "/");
    		if(!outPath.endsWith("/")) {
    			outPath = outPath + "/";
    		}
    	} else {
    		outPath = ""; 
    	}
    	outputFile.setProjectPath(outPath);
    	if(null != outputType) {
    		for(int i = 0; i < outputType.length(); i++) {
    			if ('0' == outputType.charAt(i)) {
    			} else if ('1' == outputType.charAt(i)) {
    				addOutputCodeFile(i,outputFile);
    			}
    		}
    	}
    }

    private void addOutputCodeFile(int tmpNo, OutputFile outputFile) {
    	String className = outputFile.getClassName();
    	String pck = outputFile.getPck();
    	String projectPath = outputFile.getProjectPath();
    	String pckPath = pck.replaceAll("\\.", "/");
//    	pck += "/";
    	String filepath = null; 
    	for(TemlateEnum tmpEnum : TemlateEnum.values()) {
    		if (tmpNo == tmpEnum.getTmpNo()) {
    			if (tmpEnum.getIsJavaFile()) {
    				filepath = projectPath+pckPath+"/"+tmpEnum.getPckSux()+"/"+className;
    			} else {
    				filepath = projectPath+"/"+tmpEnum.getPckSux()+"/"+pck+"."+className;
    			}
    			
    			filepath = filepath + tmpEnum.getSuffix();
    			outputInfos.put(tmpEnum.getTmpName(), filepath);
    			break;
    		}
    	}
    }
    
    public String getClassName() {
        return className;
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public String getTableName() {
        return tableName;
    }
    
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getPck() {
        return pck;
    }
    
    public void setPck(String pck) {
        this.pck = pck;
    }
    
    public Map<String, String> getOutputInfos() {
        return outputInfos;
    }
    

    public void setGenType(String genType) {
        this.genType = genType;
    }

    public String getGenType() {
        return genType;
    }

    public void setSqlFilePath(String sqlFilePath) {
        this.sqlFilePath = sqlFilePath;
    }

    public String getSqlFilePath() {
        return sqlFilePath;
    }
    
}
